<!--
 * @Author: 刘十三
 * @Date: 2024-01-02 10:23:22
 * @LastEditors: 刘十三
 * @LastEditTime: 2024-03-08 16:58:31
 * @FilePath: \NM-dev-1.3.1\dev\pages\internal\linkage\components\uploadFileList.vue
 * @Description: 内蒙多员联动 - 信息录入（附件展示）
-->
<template>
  <view class="content u-p-l-30 u-p-r-30">
    <view class="file-list">
      <view class="file-list-title">
        <text class="star" v-if="readOnly">*</text>
        门头:
      </view>
      <m-upload :deletable="!deletable" :disabled="deletable" :maxCount="picIds" width="150rpx" height="150rpx" :file-list="doorwayList" :multiple="true" index="doorwayUpload" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: doorwayFileUuid }" upApiUrl="uploadBase64ForApp" ref="filePicUpload" @on-list-change="handleUpdateDoorway" />
    </view>
    <view class="file-list">
      <view class="file-list-title">
        <text class="star" v-if="readOnly">*</text>
        许可证:
      </view>
      <m-upload :deletable="!deletable" :disabled="deletable" :maxCount="picIds" width="150rpx" height="150rpx" :file-list="rlicList" :multiple="true" index="rlicList" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: rlicFileUuid }" upApiUrl="uploadBase64ForApp" ref="rlicUpload" @on-list-change="handleUpdateRlicList" />
    </view>
    <view class="file-list">
      <view class="file-list-title">其他:</view>
      <view v-if="deletable && otherFileList.length == 0" style="padding-top: 10px;margin-left: 5px">
        <u-icon name="attach" color="#2979ff" size="28"></u-icon>
        <span style="font-size: 14px;color: #393B3D;">未上传</span>
      </view>
      <m-upload :deletable="!deletable" :disabled="deletable" :maxCount="picIds" width="150rpx" height="150rpx" :file-list="otherFileList" :multiple="true" index="otherFileList" :uploadParam="{ fiGroupCode: $FILE_GROUP_TYPE.l_diversification_attr, bizId: otherFileUuid }" upApiUrl="uploadBase64ForApp" ref="otherFileUpload" @on-list-change="handleUpdateOther" />
    </view>
  </view>
</template>
<script>
import mUpload from "@/components/m-upload.vue";
import commonService from "@/service/common/common.service";

export default {
  components: { mUpload },
  name: "uploadFileList",
  props: {
    // 门头附件id
    doorwayFileUuid: {
      type: String,
      default: "",
    },
    // 许可证附件id
    rlicFileUuid: {
      type: String,
      default: "",
    },
    // 其他附件id
    otherFileUuid: {
      type: String,
      default: "",
    },
    readOnly: {
      type: Boolean,
      default: true,
    },
    deletable: {
      type: Boolean,
      default: false, // 0,1 为true 2 为false
    },
  },
  data() {
    return {
      picIds: 10,
      doorwayList: [], // 门头 附件集合
      rlicList: [], // 许可证附件集合
      otherFileList: [], // 其他附件
    };
  },
  mounted() {
    this.getFileList();
  },
  methods: {
    getFileList() {
      Promise.all([this.doorwayFile(this.doorwayFileUuid), this.rlicFile(this.rlicFileUuid), this.getOtherFile(this.otherFileUuid)]);
    },
    doorwayFile(uuid) {
      commonService
        .goFiles(uuid, this.$FILE_GROUP_TYPE.l_diversification_attr)
        .then((rs) => {
          if (rs.success) {
            if (rs.data.length > 0) {
              rs.data.forEach((item) => {
                this.doorwayList.push({ fileId: item.gfiId, gfiId: item.gfiId });
              });
            }
          } else {
            this.$u.toast(rs.msg);
          }
        })
        .catch((err) => {});
    },
    rlicFile(uuid) {
      commonService.goFiles(uuid, this.$FILE_GROUP_TYPE.l_diversification_attr).then((rs) => {
        if (rs.success) {
          if (rs.data.length > 0) {
            rs.data.forEach((item) => {
              this.rlicList.push({ fileId: item.gfiId, gfiId: item.gfiId });
            });
          }
        } else {
          this.$u.toast(rs.msg);
        }
      });
    },
    getOtherFile(uuid) {
      commonService.goFiles(uuid, this.$FILE_GROUP_TYPE.l_diversification_attr).then((rs) => {
        if (rs.success) {
          if (rs.data.length > 0) {
            rs.data.forEach((item) => {
              this.otherFileList.push({ fileId: item.gfiId, gfiId: item.gfiId });
            });
          }
        } else {
          this.$u.toast(rs.msg);
        }
      });
    },
    handleUpdateDoorway(list) {
      console.log(list);
      if (list.length > 0) {
        this.doorwayList = [...list];
      } else {
        this.doorwayList = [];
      }
      let param = {
        type: "doorwayList",
        list: this.doorwayList,
      };
      this.$emit("updateFile", param);
    },
    handleUpdateRlicList(list) {
      if (list.length > 0) {
        this.rlicList = [...list];
      } else {
        this.rlicList = [];
      }
      let param = {
        type: "rlicList",
        list: this.rlicList,
      };
      this.$emit("updateFile", param);
    },
    handleUpdateOther(list) {
      if (list.length > 0) {
        this.otherFileList = [...list];
      } else {
        this.otherFileList = [];
      }
      let param = {
        type: "updateFile",
        list: this.otherFileList,
      };
      this.$emit("updateFile", param);
    },
    updateFile(file) {
      if (file.type == "doorwayList") {
        this.doorwayList = file.list;
      }
      if (file.type == "rlicList") {
        this.rlicList = file.list;
      }
      if (file.type == "otherFileList") {
        this.rlicList = file.list;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.file-list {
  min-height: 250rpx;
  margin-bottom: 25rpx;
  background: #ffffff;
  padding: 24rpx 15rpx 20rpx;
  border-radius: 30rpx;
  .file-list-title {
    font-size: 28rpx;
    margin: 0rpx 0rpx 10rpx 10rpx;
    color: #333333;
    position: relative;
    .star {
      color: #fa3534;
    }
  }
}
</style>
